﻿using System;
using System.Text;
using Token.Piker.BLL;
using System.Web.UI.WebControls;

namespace Token.Piker.Web.Admin.NewsAlbum
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            StringBuilder strWhere = new StringBuilder();
            if (txtKeyword.Text.Trim() != "")
            {
                strWhere.AppendFormat("AlbumName like '%{0}%'", txtKeyword.Text.Trim());
            }

            ViewNewsAlbumBLL bll = new ViewNewsAlbumBLL();
            if (pagerList.CurrentPageIndex == 1)
            {
                gridView.DataSource = bll.GetList(pagerList.PageSize, strWhere.ToString(), "ShotTime DESC");
            }
            else
            {
                gridView.DataSource = bll.GetListByPage(strWhere.ToString(), "ShotTime DESC", pagerList.StartRecordIndex, pagerList.EndRecordIndex);
            }
            gridView.DataBind();
            pagerList.RecordCount = bll.GetRecordCount(strWhere.ToString());
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void pagerList_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack && !IsCallback)
            {
                BindData();
            }
        }

        protected void ChangeState(object sender, EventArgs e)
        {
            LinkButton lkbChangeState = sender as LinkButton;
            int id = Convert.ToInt32(lkbChangeState.CommandArgument);
            NewsAlbumBLL newsAlbumBLL = new NewsAlbumBLL();
            Token.Piker.Model.NewsAlbum album = newsAlbumBLL.GetModel(id);
            if (lkbChangeState.Text == "正常")
            {
                album.Flag = 1;
            }
            else
            {
                album.Flag = 0;
            }

            newsAlbumBLL.Update(album);
            BindData();
        }
    }
}